package net.xdclass.xdclasssky.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import net.xdclass.xdclasssky.mapper.ProductMapper;
import net.xdclass.xdclasssky.model.ProductDO;
import net.xdclass.xdclasssky.service.ProductService;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * 小滴课堂,愿景：让技术不再难学
 *
 * @Description
 * @Author 二当家小D，微信：xdclass6
 * @Remark 有问题直接联系我，源码-笔记-技术交流群
 * @Version 1.0
 **/

@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductMapper productMapper;

    @Override
    @Trace
    public List<ProductDO> list() {


        return test();
    }


    @Trace
    @Tags(
            {
                    @Tag(key = "test-output", value = "returnedObj")
            }
    )
    public List<ProductDO> test(){

        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return productMapper.selectList(new QueryWrapper<>());
    }



    @Trace
    @Tags(
            {
                    @Tag(key = "detail-input", value = "arg[0]"),
                    @Tag(key = "detail-output", value = "returnedObj")
            }
    )
    @Override
    public ProductDO detail(long productId) {
        return productMapper.selectOne(new QueryWrapper<ProductDO>().eq("id", productId));
    }


}
